Attribute VB_Name = "modODBC"
'---------------------------------------------------------------------------------------
'Module     : modODBC
'Author     : Chris Elwell
'Purpose    : This is an example of a CIC integration module. This is for demostration
'           purposes only. You must write the code required to get/writeback data from/to
'           your customer's data source.
'
'           This example uses the AddrVerify.mdb. A DSN is setup as AddrVerify.
'           Regardless of the integration method, CICs must have a module that contains
'           specific sub routines. All of these subs/functions listed below must exist
'           as they are called from the main program.
'
'           Public Function GetData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID field loses focus. This is where you would code to
'               get order data from a customer and populate the screen fields. You can create
'               and call as many support routines as necessary. Also, this routine should
'               return a boolean True if getting the order data was succesful and a boolean
'               False if it was not.
'           Public Function GetPickupData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID on the FedEx Returns for field loses focus.
'               This operates the same as GetData above but for use obtaining the Pickup From
'               address info on the Call Tag/Express Tag form.
'           Public Sub WriteReply() - this is called after a successful shipment. A typical
'               use would be to write FXRS reply data back to a customer's system, but can be
'               used for anything that you want to have happen after a package is shipped.
'           Public Sub WriteReturnReply() - this is called after a successful Return Label
'               shipment. Use this to write FXRS reply data back to the customer's system.
'               This is called on both regular and online return labels.
'           Public Sub WriteBOLReply() - this is called after a successful FedEx Freight BOL shipment.
'           Public Sub WriteBatchEditReply() - this is called after a successful Batch Error
'           Edit shipment.
'           Public Sub WriteTagReply() - this is called after a successful Call/Express Tag
'           Public Sub WriteCancelTagReply() - this is called after a Call/Express Tag is Canceled
'           Public Sub WriteError() - this is called after an error is returned from FXRS.
'           Public Sub WriteDelete(ByVal strTracking As String) - this is called after a
'               package is successfully deleted.
'           Public Sub WriteReturnDelete(ByVal strTracking As String) - this is called after
'               a successful Return Label delete. Use this to write FXRS reply data back to
'               the customer's system. This is called on both regular and online return labels.
'           Public Sub AfterClose() - this is called after FXRS is closed.
'           Public Sub AfterLocationChange() - this is called after the Current Location is changed
'               on frmShip.
'           Public Sub BeforeClose() - this is called just before an FXRS close transaction
'               is sent and must return a boolean True for the Close to proceed.
'           Public Function BeforeShip() - Return TRUE to continue shipment, False to cancel.
'           Public Sub Initialize() - this is called once on program execution.
'           Public Sub BeforeBatch() - this is called before processing a batch file.
'           Public Sub BeforeBatchShip() - this is called before each individual batch
'                                          transaction.
'           Public Sub AfterBatchShip() - this is called after each shipment in batch processing.
'           Public Sub AfterBatch() - this is called after a completed batch shipment.
'           Public Sub AfterAddrLookup() - this is called after cboCustID, cboContact, and
'                                          cboCompany lose focus
'           Public Sub AfterDeptLostFocus() - this is called after cboDept or f38 loses focus.
'           Public Sub AfterAddrVerifyUpdate() - this is called after the Update button is
'                                            clicked on the Verify Address form.
'           Public Sub AfterAddrVerify(ByVal intStatusCode As Integer) - this is called after
'               Address Verification. The status code indicates 1 address verified, 2 there was
'               a soft error returned, 3 there was a hard error returned.
'NEW        Public Function BuildCustomSPLabel(ByVal strLabel As String) As String - this is called
'               from BuildSPEPLLabel and BuildSPZPLLabel in modSmartPost. This allow CICs to create
'               custom SmartPost labels in either ZPL or EPL.
'---------------------------------------------------------------------------------------
Option Explicit

Dim m_cnCustDB As ADODB.Connection
Dim m_rsCustOrder As ADODB.Recordset
'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetData(ByVal strKey As String) As Boolean
    
    On Error GoTo Handler
    
    Dim strSelect
    Dim TheAddr As AddrData
    Dim blnRes As Boolean
    
    strSelect = "SELECT * FROM Addresses WHERE f1 = " & strKey

    If Not Connect Then Exit Function   'set conection and recordset

    m_rsCustOrder.CursorLocation = adUseClient
    m_rsCustOrder.Open strSelect, m_cnCustDB, adOpenStatic     'run SELECT

    Set m_rsCustOrder.ActiveConnection = Nothing
    m_cnCustDB.Close

    If m_rsCustOrder.BOF And m_rsCustOrder.EOF Then
        'No records found for that order number
        m_rsCustOrder.Close
        GetData = False
        Exit Function
    End If
    
    'Assign the values from the customer's order to the appropriate Ship form fields
    'and any special svcs forms' fields, if applicable.
    With frmShip
        .f12 = m_rsCustOrder!f12 & ""
        .f11 = m_rsCustOrder!f11 & ""
        .f13 = m_rsCustOrder!f13 & ""
        .f14 = m_rsCustOrder!f14 & ""
        .f15 = m_rsCustOrder!f15 & ""
        .f16 = m_rsCustOrder!f16 & ""
        .f17 = m_rsCustOrder!f17 & ""
        .f50 = m_rsCustOrder!f50 & ""
        .f1670 = "1"
        .f1273 = "01"
        .f18 = "8135551212"
        .f25 = "Testing 1-2-3"
        .f1274 = "92"
        
        'Assign addr fields for the VERIFI Res transaction
        With TheAddr
            .Company = m_rsCustOrder!f11 & ""
            .Addr1 = m_rsCustOrder!f13 & ""
            .Addr2 = m_rsCustOrder!f14 & ""
            .City = m_rsCustOrder!f15 & ""
            .St = m_rsCustOrder!f16 & ""
            .Zip = m_rsCustOrder!f17 & ""
        End With
        
        'If it's Res True is returned
        blnRes = IsResidential(TheAddr)
            
        'If it's Res and the service is Ground change to FHD.
        If blnRes And Left(.f1274, 2) = "92" Then
            .f1274 = "90"
            Call SetMessage("Residential - Changed to FHD", , &HDF)
        Else
            Call SetMessage("")
        End If
'==============================================================================================
'Example of how to set SmartPost defaults for Service, Class & Sub-Class
'----------------------------------------------------------------------------------------------
        If Left(.f1274, 2) = "99" Then
            .cboClass = "B"
            .cboSubClass = "P"
        End If

        With frmCOD
            .chkCOD1stPiece = 1
        End With

'==============================================================================================
'Example of how to programmatically set the current FSMS IP address. Pass the desired value as
'configured on the Server tab in Setup.
'----------------------------------------------------------------------------------------------
'        If Not SetCurrentFSMSIP("FXRS1") Then
'            MsgBox "Invalid FSMS IP Address. Please set manually"
'        End If
'==============================================================================================
'Example of how to set Special Svcs forms' fields. This is an Email example. AssignFormGlobalVars
'is a Public sub on every Special Svc form. Use it to set the global vars or the feilds won't be
'sent in the transaction.
'----------------------------------------------------------------------------------------------
'        With frmEmail
'            .f1201 = "a.person@shipper.com"         'Shipper Email
'            .f1553 = 1                              'Shipper gets Delivery Notification
'            .f1961 = 1                              'Shipper gets Exception Notification
'            .f1202 = m_rsCustOrder!RecipEmail & ""  'Recipient Email
'            .f1557 = 1                              'Recipient gets Shipment Notification
'            .f1962 = 1                              'Recipient gets Exception Notification
'            .AssignFormGlobalVars                   '*** REQUIRED TO SET GLOBAL VARS ***
'        End With
'        .chkEmailAlert = 1                          'Have to check Email Alert checkbox for EMails
'        frmEmail.Hide                               'Hides the frmEmail shown by line above
'==============================================================================================
'Example of how to do Parse Pak through integration - Note customer must have total pkgs and
'       total wgt in their system else you have to create a form to capture these fields from
'       user input. This assumes that the customer has a field called TotalWgt and TotalPkgs in
'       their datasource.
'----------------------------------------------------------------------------------------------
'        'Get total pieces
'        intTotalPkgs = Val(m_rsCustOrder!TotalPkgs & "")
'
'        'Get total wgt
'        intTotalWgt = Val(m_rsCustOrder!TotalWgt & "")
'
'        'ReDim array for individual wgts
'        ReDim intWgt(intTotalPkgs)
'
'        'Initialize temp wgt var
'        intTempWgt = 0
'
'        'Delete any current MPS for this order in case they entered Order ID twice
'        Call DeleteMPS(strKey)
'
'        'Check to ensure there are multiple pieces and a value for wgt
'        If intTotalWgt > 0 And intTotalPkgs > 1 Then
'
'            'Calc wgt per piece. Can also add calc for Dec Val here if needed
'            For i = 0 To intTotalPkgs - 1
'                If i < intTotalPkgs - 1 Then
'                    intWgt(i) = CInt(intTotalWgt / intTotalPkgs)
'                    'Temp total
'                    intTempWgt = intTempWgt + intWgt(i)
'                'Last piece subtract the temp total from the total wgt
'                Else
'                    intWgt(i) = intTotalWgt - intTempWgt
'                End If
'
'                'Insert into MPS table - note values are being pulled fro Ship form. DecVal can be calculated per
'                '   piece or entered on the first piece only as in the example below
'                If i = 0 Then
'                    Call InsertMPS(strKey, Trim(CStr(intWgt(i))), .f57(0), .f58(0), .f59(0), .f26, .f25, .f3056, .f3057, "", "")
'                Else
'                    Call InsertMPS(strKey, Trim(CStr(intWgt(i))), .f57(0), .f58(0), .f59(0), "", .f25, .f3056, .f3057, "", "")
'                End If
'            Next
'
'            'Must call this to show # pkgs on Ship form, which triggers MPS shipment.
'            Call frmMPS.UpdateMPSGrid(strKey)
'
'        'Else set to a single piece and whatever wgt was in customer system.
'        Else
'            .f1670 = Trim(CStr(intTotalWgt))
'            .f116 = "1"
'        End If
'
'==============================================================================================
'Examples Service Conversion test - assume ShipVia is service in the customer database.
'       This example show how to set a default service to Ground if the ShipVia is not on
'       the Setup Service Conv tab.
'----------------------------------------------------------------------------------------------
'           Dim strSvcCode As String
'           'Get service code
'           strSvcCode = ConvertServiceType(m_rsCustOrder!ShipVia)
'           'If strSvcCode is empty set to Ground
'           .f1274 = IIf(strSvcCode <> "", strSvcCode, "92")
'==============================================================================================
'Example use of SetCurrentAccount to programmatically change the current shipping account
'       Assume customer has a Location field that indicates the shipping account. Set up a
'       Select Case statement for each possible account. Pass FedEx acct# to SetCurrentAccount.
'----------------------------------------------------------------------------------------------
'        Select Case m_rsCustOrder!Location
'            Case "ABC Co."
'                If Not SetCurrentAccount("123456789") Then
'                    MsgBox "Acct# 123456789 not found. Please select account from Location box", vbExclamation, "Error"
'                End If
'            Case "XYZ Co."
'                If Not SetCurrentAccount("987654321") Then
'                    MsgBox "Acct# 987654321 not found. Please select account from Location box", vbExclamation, "Error"
'                End If
'            Case "123 Co."
'                If Not SetCurrentAccount("111222333") Then
'                    MsgBox "Acct# 111222333 not found. Please select account from Location box", vbExclamation, "Error"
'                End If
'        End Select
'==============================================================================================
'Example use of the SetMessage sub
'----------------------------------------------------------------------------------------------
'    Call SetMessage("Destination state is: " & m_rsCustOrder!f16, 16, vbBlack, True)
'==============================================================================================
'Example of how to trigger Auto Address Verification - set focus to Zip then to another field, in
'       this case the receipient Phone. Auto AV is triggered when Zip field loses focus.
'----------------------------------------------------------------------------------------------
'        .f17.SetFocus
'        .f18.SetFocus
'==============================================================================================
'Example of how to automatically ship if all required shipping info is populated
'----------------------------------------------------------------------------------------------
'       'If using a scale set focus to weight field
'       .f1670.SetFocus
'       'Pause to allow scale to be read. This will pause for a 1/2 second, adjust if needed.
'       Call Pause(.5)
'       SendKeys "{F12}"
'==============================================================================================
    End With
    
    GetData = True
Release:
    Call CloseCustDB
    Exit Function
Handler:
    MsgBox Err.Description, , "modODBC.GetData"
    Resume Release
End Function
'---------------------------------------------------------------------------------------
' Procedure : GetPickupData()
' DateTime  : 1/30/2006
' Purpose   : REQUIRED SUB. Called from frmAddTags.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetPickupData(ByVal strKey As String) As Boolean
    
    Dim strSelect As String
    
    strSelect = "SELECT * FROM Addresses WHERE f1 = " & strKey

    If Not Connect Then Exit Function   'set conection and recordset

    m_rsCustOrder.CursorLocation = adUseClient
    m_rsCustOrder.Open strSelect, m_cnCustDB, adOpenStatic     'run SELECT

    Set m_rsCustOrder.ActiveConnection = Nothing
    m_cnCustDB.Close

    If m_rsCustOrder.BOF And m_rsCustOrder.EOF Then
        'No records found for that order number
        m_rsCustOrder.Close
        GetPickupData = False
        Exit Function
    End If
    With frmAddTags
        .f12.Text = m_rsCustOrder!f12 & ""
        .f11.Text = m_rsCustOrder!f11 & ""
        .f13.Text = m_rsCustOrder!f13 & ""
        .f14.Text = m_rsCustOrder!f14 & ""
        .f15.Text = m_rsCustOrder!f15 & ""
        .f16.Text = m_rsCustOrder!f16 & ""
        .f17.Text = m_rsCustOrder!f17 & ""
    End With
    
    GetPickupData = True

Release:
    Call CloseCustDB
    Exit Function

Handler:
    MsgBox Err.Description, , "modODBC.SQLSelect"
    Resume Release

End Function
'---------------------------------------------------------------------------------------
' Procedure : WriteReply()
' DateTime  : 2/14/2005
' Purpose   : REQUIRED SUB. Called after a successful ship transaction.
'             This example shows how to obtain multiple occurrence fields from the
'             FXRS reply and how to obtain multiple occurrence fields included in the
'             input transaction but not returned in the FXRS reply.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReply()
    
    On Local Error GoTo Handler
    
    Dim i As Integer
    Dim j As Integer
    
    Dim f1 As String                    'OrderID (in TransID field)
    Dim f34 As String                   'Gross chg
    Dim f35 As String                   'Total surcharges
    Dim f37 As String                   'Net charge
    Dim f60 As String                   'Billed weight
    Dim f116 As String                  'Num pkgs
    Dim strInsert As String             'SQL INSERT
    Dim strMPS As String                'MPS SELECT query
    Dim rsMPS As New ADODB.Recordset    'Used to capture MPS input fields
    Dim f3056 As String                 'PO#
    
    If Not Connect Then Exit Sub

    'Declare string arrays for trk#s and declared values
    Dim str29() As String
    Dim str26() As String

    Dim intNumPkgs As Integer

    'Get # of pkgs
    intNumPkgs = Val(frmShip.f116)

    'ReDim the string array using the # of pkgs
    ReDim str29(intNumPkgs)
    ReDim str26(intNumPkgs)

    'Added 4/14/05 for SmartPost - see Else statement below
    If g_str1274 <> "99" Then
        'Get the fields you wish from the reply transaction
        With frmShip.g_clsParser
            For i = 0 To .TotalFields - 1
                Select Case .Field(i)
                    Case "1"
                        f1 = .Data(i)           'TransID
                    Case "29"
                        str29(1) = .Data(i)     'First trk#
                    Case "35"
                        f35 = .Data(i)          'Total Surcharges
                    Case "37"
                        f37 = .Data(i)          'Net Charges
                    Case "60"
                        f60 = .Data(i)          'Billed Weight
                    Case "116"
                        f116 = .Data(i)         '# Pkgs
                End Select

                'Get multiple occurrence tracking #s
                'Note: This will capture Int'l MPS child trk#s as well as domestic MPS
                If intNumPkgs > 1 And frmShip.chkDuplicate = 0 Then
                    For j = 2 To intNumPkgs
                        If .Field(i) = "29-" & Trim(Str(j)) Then str29(j) = .Data(i)
                    Next
                End If
            Next
        End With

        'Query to get fields saved in MPS table for MPS transactions
        strMPS = "SELECT * FROM MPS WHERE f1 = '" & f1 & "'"
        strMPS = strMPS & " AND Workstation = '" & g_strComputerName & "'"

        'Open recordset
        rsMPS.Open strMPS, g_connFSMSClient, adOpenStatic, adLockBatchOptimistic

        'Loop through the MPS recordset and assign the Declared Value fields
        'Note: You can also capture any other MPS field using this loop by declaring
        'variables for those data element assigning the values here.
        i = 1
        If Not rsMPS.EOF Then
            Do Until rsMPS.EOF
                str26(i) = rsMPS!g_str26 & ""
                rsMPS.MoveNext
                i = i + 1
            Loop
        Else
            str26(1) = g_str26
        End If
    'Added 4/14/05 for SmartPost
    Else
        str29(1) = Right(g_strDCB, 20)
        f1 = g_str1
        f34 = g_str37   'Gross chgs are the same as net charges
        f37 = g_str37   'Net charges
        str26(1) = "0"  'Dec Val
        f60 = g_str60   'Billed wgt
        f116 = "1"      'Num pkgs
    End If

    'Perform Insert query for each package
    For i = 1 To intNumPkgs
        If str29(i) <> "" Then
            strInsert = "INSERT INTO Shipments VALUES(" & SingleQuotes(str29(i)) & ","
            strInsert = strInsert & SingleQuotes(f1) & ","
            strInsert = strInsert & SingleQuotes(FormatCharges(f35)) & ","
            strInsert = strInsert & SingleQuotes(FormatCharges(f37)) & ","
            strInsert = strInsert & SingleQuotes(str26(i)) & ","
            strInsert = strInsert & SingleQuotes(f60) & ","
            strInsert = strInsert & SingleQuotes(f116) & ","
            strInsert = strInsert & "'Shipped')"

            m_cnCustDB.Execute strInsert
        End If
    Next
  
   
'==============================================================================================
'Example of how to convert a FedEx service code back to the customer code. This requires that
'       the customer codes be defined in Setup on the Service Conv tab.
'----------------------------------------------------------------------------------------------
'    Dim strCustSvcCode As String
'
'    'For Domestic and Intl shippers
'    strCustSvcCode = ConvertServiceTypeBack(g_str1274, IIf(g_str50 = "US", True, False))
'
'    'For Domestic-only shippers
'    strCustSvcCode = ConvertServiceTypeBack(g_str1274)
'
'    'For Intl-only shippers
'    strCustSvcCode = ConvertServiceTypeBack(g_str1274, False)
'----------------------------------------------------------------------------------------------
    
Release:
    Call CloseCustDB
    If rsMPS.State = adStateOpen Then rsMPS.Close
    Set rsMPS = Nothing
    Exit Sub

Handler:
    MsgBox Err.Description, , "modODBC.WriteReply"
    Resume Release
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnReply()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnReply()
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBOLReply()
' DateTime  : 1/11/2006
' Purpose   : REQUIRED SUB. Called after a successful FedEx Freight BOL transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBOLReply()
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBatchEditReply()
' DateTime  : 1/17/2006
' Purpose   : REQUIRED SUB. Called after a successful Batch Error Edit transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBatchEditReply()
    
End Sub
' Procedure : WriteTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteTagReply()
    
End Sub
' Procedure : WriteCancelTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Cancel Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteCancelTagReply()
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnDelete()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label delete transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnDelete(ByVal strTracking As String)
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteError()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an FXRS Error reply transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteError()
    
    MsgBox "Shipping Error: " & g_str3, vbCritical, "FSMS Error"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteDelete()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             successful FXRS Delete.
' Called    : frmShip g_clsParser_Parsecomplete() event on FSMS 123 reply
'---------------------------------------------------------------------------------------
'
Public Sub WriteDelete(ByVal strTracking As String)
    On Local Error GoTo Handler
    Dim strUpdate As String
    
    If Not Connect Then Exit Sub
    
    strUpdate = "UPDATE Shipments SET [Status] = 'Deleted'" & _
                " WHERE TrkNum = '" & strTracking & "'"
    
    m_cnCustDB.Execute strUpdate
    
Release:
   Call CloseCustDB
   Exit Sub
Handler:
    MsgBox Err.Description, , "modODBC.WriteDelete"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : Connect()
' DateTime  : 7/5/2004
' Purpose   : NOT REQUIRED. Open connection to ODBC test DSN. Instantiate module level recordset.
'---------------------------------------------------------------------------------------
'
Private Function Connect() As Boolean
    On Local Error GoTo Handler
    Dim strDSN As String
    
    Set m_cnCustDB = New ADODB.Connection
    Set m_rsCustOrder = New ADODB.Recordset
    
    If m_cnCustDB.State <> adStateOpen Then   'if connection is not open then do so
        m_cnCustDB.Open "DSN=AddrVerify"
    End If
    
    Connect = True
    
    Exit Function

Handler:
    MsgBox Err.Description, , "modODBC.Connect"
    Call CloseCustDB        'kill connection and recordset

End Function
'---------------------------------------------------------------------------------------
' Procedure : CloseCustDB()
' DateTime  : 7/5/2004
' Purpose   : NOT REQUIRED. Close connection and recordset objects and set = to nothing.
'---------------------------------------------------------------------------------------
'
Public Sub CloseCustDB()
    On Local Error GoTo Handler
    
    If m_cnCustDB.State = adStateOpen Then m_cnCustDB.Close
    If m_rsCustOrder.State = adStateOpen Then m_rsCustOrder.Close
    
    Set m_cnCustDB = Nothing      'kill connection
    Set m_rsCustOrder = Nothing      'kill recordset
    
    Exit Sub
Handler:
    MsgBox Err.Description, , "modODBC.CloseCustDB"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterClose()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Sub AfterClose()
    'Display a message if there is > 10,000 pkgs over 14 days old
    If PurgeCheck(14) > 10000 Then
        MsgBox "The database needs to be purged.", vbExclamation, "Maintenance Notification"
        frmPurge.Show vbModeless, frmShip
    End If
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : BeforeClose()
' DateTime  : 7/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed before
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Function BeforeClose() As Boolean

    BeforeClose = True

End Function
'---------------------------------------------------------------------------------------
' Procedure : BeforeShip()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShip() As Boolean

    BeforeShip = True

End Function
'---------------------------------------------------------------------------------------
' Procedure : Initialize()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution.
'---------------------------------------------------------------------------------------
'
Public Sub Initialize()
    
'==============================================================================================
'Example of how to change screen field captions - NOTE: Does not work for P.O. # field on Ship form
'----------------------------------------------------------------------------------------------
'    With frmShip
'        .Label1(11).Caption = "OHL OrderID"    'Reference field label
'        .Label1(13).Caption = "B.O.L. Number"  'Inv# field label
'        .SSTab1.TabCaption(2) = "File Ship"    'Batch tab caption
'    End With
'    With frmMPS
'        .Label22.Caption = "OHL OrderID"       'Reference field label MPS form
'        .Label25.Caption = "B.O.L. Number"     'Inv# field label MPS form
'    End With

End Sub
'---------------------------------------------------------------------------------------
' Procedure : BeforeBatch()
' DateTime  : 20070621-01 Changed BeforeBatch to return a boolean
' Purpose   : REQUIRED SUB. Called before an entire batch is processed.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatch()
    
    BeforeBatch = True

End Function
'---------------------------------------------------------------------------------------
' Procedure : BeforeBatchShip()
' DateTime  : 20070822-02 Modified BeforeBatchShip to return a Boolean.
' Purpose   : REQUIRED SUB. Called just before a batch transaction is sent to the server.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatchShip()

'==============================================================================================
'Example on how to add Alt Ret Addr to Batch shipments
'
'----------------------------------------------------------------------------------------------
'    If g_str1586 = "Y" Then
'
'        'Remove 99,""
'        g_strTrans = Left(g_strTrans, Len(g_strTrans) - 5)
'        'Add Alt Ret Fields
'        TransactionBuilder g_strTrans, 1586, "Y"
'        TransactionBuilder g_strTrans, 1485, g_str1485
'        TransactionBuilder g_strTrans, 1486, g_str1486
'        TransactionBuilder g_strTrans, 1487, g_str1487
'        TransactionBuilder g_strTrans, 1488, g_str1488
'        TransactionBuilder g_strTrans, 1489, g_str1489
'        TransactionBuilder g_strTrans, 1490, g_str1490
'        TransactionBuilder g_strTrans, 1491, g_str1491
'        TransactionBuilder g_strTrans, 1492, g_str1492
'        TransactionBuilder g_strTrans, 1585, g_str1585
'        TransactionBuilder g_strTrans, 99, ""
'
'    End If
'----------------------------------------------------------------------------------------------
    
    BeforeBatchShip = True
    
End Function
'---------------------------------------------------------------------------------------
' Procedure : AfterBatchShip()
' DateTime  : 10/28/2005
' Purpose   : REQUIRED SUB. Called just after a batch transaction has been processed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatchShip()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterBatch()
' DateTime  : 4/6/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a batch shipment has been completed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatch()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrLookup()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboCustID, cboContact, or cboCompany loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrLookup()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterDeptLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterDeptLostFocus()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerifyUpdate()
' DateTime  : 9/13/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an address has been updated on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerifyUpdate()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 3/06/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             the Current Location has been changed on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLocationChange()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 5/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             Address Verification. Three possible status codes are passed. See comments
'             below.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerify(ByVal intStatusCode As Integer)

    Select Case intStatusCode
        Case 1
            'Address is verfified
            'Example of how to AutoShip when an address is verified
            'SendKeys "{F12}"
            
        Case 2
            'Soft error
        Case 3
            'Hard error
    End Select

End Sub
'---------------------------------------------------------------------------------------
' Procedure : BuildCustomSPLabel()
' DateTime  : 20070620-04
' Purpose   : REQUIRED SUB. Can be used as hook to create custom EPL or ZPL buffer labels
'             for SmartPost.
'---------------------------------------------------------------------------------------
'
Public Function BuildCustomSPLabel(ByVal strLabel As String) As String

    BuildCustomSPLabel = strLabel
    
End Function
